<?php
    Yii::app()->clientScript->registerScriptFile(Yii::app()->request->baseUrl . '/js/sprintf.js');
    Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl . '/css/datepicker.css', CClientScript::POS_END);
    Yii::app()->clientScript->registerScript('datepicker', "$('.datepicker').datepicker({autoclose:true,
        clearBtn:true,
        todayBtn:true,
        todayHighlight:true,
        format: 'yyyy-mm-dd',
        language:'zh-CN'});", CClientScript::POS_END);

    $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
        'id' => 'expenses-form',
        'enableAjaxValidation' => true,
    ));
?>

<p class="help-block">Fields with <span class="required">*</span> are required.</p>

<?php echo $form->errorSummary($model); ?>

<?php echo $form->textFieldRow($model, 'user_id', array('class' => 'span1', 'readonly' => true)); ?>
<!-- model: select customer, start -->
<?php $this->beginWidget('bootstrap.widgets.TbModal', array('id' => 'chooseStaffModal')); ?>

<div class="modal-header">
    <a class="close" data-dismiss="modal">&times;</a>
    <h4><?php echo t('Choose Staff'); ?></h4>
</div>

<div class="modal-body">
    <?php
        //list customers who under the user
        $dataProvider = new CActiveDataProvider('User', array(
            'pagination' => array(
                'pageSize' => 10,
            ),
        ));
        $this->widget('bootstrap.widgets.TbGridView', array(
            'type' => 'bordered',
            'dataProvider' => $dataProvider,
            //'filter' => $users,
            'template' => "{items}{pager}",
            'columns' => array(
                array('name' => 'id', 'header' => '#'),
                array('name' => 'user_code', 'header' => t('User Code')),
                array('name' => 'profile.firstname', 'header' => t('First Name')),
                array('name' => 'profile.lastname', 'header' => t('Last Name')),
                array('name' => 'status', 'header' => t('Status')),
                array(
                    'class' => 'bootstrap.widgets.TbButtonColumn',
                    'htmlOptions' => array(
                        'style' => 'width: 50px',
                    ),
                    'template' => '{chooseStaff}',
                    'buttons' => array(
                        'chooseStaff' => array(
                            'label' => 'Choose', // text label of the button
                            'url' => '$data["id"]', // a PHP expression for generating the URL of the button
                            'imageUrl' => Yii::app()->request->baseUrl . '/images/choose-32.png', // image URL of the button. If not set or false, a text link is used
                            'options' => array(
                                'onclick' => 'var param=$(this).attr(\'href\');
                                document.getElementById(\'Expenses_user_id\').value = param;',
                                'data-dismiss' => 'modal',
                                'icon' => 'icon-ok',
                            ), // HTML options for the button tag
                            'visible' => 'true', // a PHP expression for determining whether the button is visible
                        )
                    ),
                ),
            ),
        ));
    ?>
</div>

<div class="modal-footer">
    <?php
        $this->widget('bootstrap.widgets.TbButton', array(
            'label' => t('Close'),
            'url' => '#',
            'htmlOptions' => array('data-dismiss' => 'modal'),
        ));
    ?>
</div>

<?php $this->endWidget(); ?>
<!-- the following style is used for hack TbButton's position, that move up 10px to align with input box. -->
<style>
    .aligntop {margin-bottom: 10px;}
</style>
<!-- hack end -->

<?php
    $this->widget('bootstrap.widgets.TbButton', array(
        'label' => t('Choose...'),
        'type' => 'primary',
        'htmlOptions' => array(
            'data-toggle' => 'modal',
            'data-target' => '#chooseStaffModal',
            'class' => 'aligntop',
        ),
    ));
?>
<!-- model: select customer, end -->

<?php echo $form->textFieldRow($model, 'item', array('class' => 'span5', 'maxlength' => 500)); ?>

<?php
    echo $form->textFieldRow($model, 'amount', array('class' => 'span2',
        'maxlength' => 10,
        'onkeyup' => 'this.value=this.value.replace(/[^\d.]/,\'\')',
        'onblur' => 'this.value=sprintf(\'%.2f\', this.value);',
        'onfocus' => 'this.select();',));
?>

<?php echo $form->textFieldRow($model, 'on_date', array('class' => 'span2 datepicker')); ?>

<?php echo $form->textAreaRow($model, 'remark', array('class' => 'span5', 'maxlength' => 255)); ?>

<?php //echo $form->textFieldRow($model,'createtime',array('class'=>'span5'));  ?>

<?php
    echo $form->hiddenRow($model, 'updateby_user_id', array(
        'value' => Yii::app()->user->id,
    ));
?>

<?php //echo $form->textFieldRow($model,'modifytime',array('class'=>'span5'));     ?>

<div class="form-actions">
    <?php
        $this->widget('bootstrap.widgets.TbButton', array(
            'buttonType' => 'submit',
            'type' => 'primary',
            'label' => t($model->isNewRecord ? 'Create' : 'Save'),
            //'htmlOptions' => array('class' => 'span1'),
            'icon' => 'icon-ok icon-white',
        ));
    ?>
    <?php
        $this->widget('bootstrap.widgets.TbButton', array(
            'buttonType' => 'Button',
            'type' => 'primary',
            'label' => t('Cancel'),
            'url' => Yii::app()->createURL('expenses/index'),
            //'htmlOptions' => array('class' => 'span1'),
            'icon' => 'icon-remove icon-white',
        ));
    ?>

</div>

<?php $this->endWidget(); ?>
